#!/usr/bin/python3
#-*-coding:utf-8-*-

###############################################################
## Name       : cmp_rtl
## Author     : gaojiaming
## Date       : Thu Aug 18 11:20:34 CST 2022
## Description:
##
##
###############################################################

import sys
import os
import re
import argparse

def input_args_proc():
    global top
    global lst
    parser = argparse.ArgumentParser(description="argparse info")
    parser.add_argument('-o', action='store_true', default=False, help='open this script')
    parser.add_argument('-t', help='top_module')
    parser.add_argument('-f', help='filelist.lst')
    result = parser.parse_args()
    if result.o == True:
        os.system("gvim %s" % __file__)
        sys.exit(0)
    top = result.t
    lst = result.f
pass

def vcs_cfg():
    global vcs_cmp

    log_path  = "$PROJ_ROOT/cmp/{0}/log".format(top)
    exec_path = "$PROJ_ROOT/cmp/{0}/exec".format(top)
    simv_path = exec_path + "/simv"
    log_name  = log_path + "/" + top + ".log"

    os.system("rm -rf " + exec_path)
    os.system("mkdir -p " + log_path)
    os.system("mkdir -p " + exec_path)

    vcs_cmp = "vcs "
    vcs_cmp += "-f {0} -l {1} -o {2} +libext+.v ".format(lst, log_name, simv_path)
    vcs_cmp += "+v2k +define+RTL_SAIF +nospecify +vpi +plusarg_save +nospecify +udpsched "
    vcs_cmp += "+vcs+lic+wait -v2005 "
    #vcs_cmp += "-sverilog "
    vcs_cmp += "-full64 -debug_acc+all -lca -kdb "
    vcs_cmp += "-top {0} ".format(top)
    vcs_cmp += "-timescale=1ns/1ps -unit_timescale=1ns/1ps "
pass

def main():
    input_args_proc()
    vcs_cfg()
    os.system(vcs_cmp)
    os.system(r"rm -rf stack.info.*")
    os.system(r"rm -rf csrc")

if __name__ == "__main__":
    print("%s is working" % __file__)
    main()
